<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('体验版列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <div class="select-list">
                    <ul>
                        <li>
                            小程序名称：<input type="text" name="appletName"/>
                        </li>
                        <li>
                            店铺名称：<input type="text" name="shopName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-success multiple" onclick="addToTemplate(-1,1)" shiro:hasPermission="back:wechatOpen:submitAudit">-->
                <!--<i class="fa fa-upload"></i> 批量提交审核-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple" onclick="addToTemplate(-1,0)" shiro:hasPermission="back:wechatOpen:rollbackAudit">-->
                <!--<i class="fa fa-close"></i> 批量撤回审核-->
            <!--</a>-->
            <!--<a class="btn btn-primary multiple" onclick="addToTemplate(-1,0)" shiro:hasPermission="back:wechatOpen:releaseAudit">-->
                <!--<i class="fa fa-check"></i> 批量发布-->
            <!--</a>-->

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "back/wechatOpen";
    var submitAuditFlag = [[${@permission.hasPermi('back:wechatOpen:submitAudit')}]];
    var rollbackAuditFlag = [[${@permission.hasPermi('back:wechatOpen:rollbackAudit')}]];
    var releaseAuditFlag = [[${@permission.hasPermi('back:wechatOpen:releaseAudit')}]];
    const appletDemoStatusDict = [[${@dict.getType('applet_demo_status')}]];
    $(function () {
        var options = {
            url: prefix + "/commitList",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "小程序体验版列表",
            height: 600,
            columns: [
                {
                    field: 'id',
                    title: '提交ID'
                },
                {
                    field: 'templateId',
                    title: '模板ID',
                    sortable:true
                },
                {
                    field: 'shopName',
                    title: '店铺名称'
                },
                {
                    field: 'appletName',
                    title: '小程序名称'
                },
                {
                    field: 'appletAppId',
                    title: '小程序appId'
                },
                {
                    field: 'demoQrCode',
                    title: '体验版二维码',
                    formatter: function (value, row, index) {
                        return $.common.sprintf("<img class='img-circle img-sm' data-height='%s' data-width='%s' data-target='%s'  style='border-radius: 0;' src='%s' data-src='%s'/>", 400, 'auto', 'self', value, value);
                    }
                },
                {
                    field: 'extJson',
                    title: '提交参数',
                    visible:false
                },
                {
                    field: 'userVersion',
                    title: '版本号'
                },
                {
                    field: 'userDesc',
                    title: '版本描述'
                },
                {
                    field: 'status',
                    title: '状态',
                    sortable:true,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(appletDemoStatusDict, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '提交人'
                },
                {
                    field: 'createTime',
                    title: '提交时间',
                    sortable:true
                },{
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        switch (parseInt(row.status)) {
                            case 1:
                                actions.push('<a class="btn btn-success btn-xs ' + submitAuditFlag + '" href="#" onclick="submitAudit(\'' + row.id + '\')"><i class="fa fa-upload">提交审核</i></a> ');
                                break;
                            case 2:
                                actions.push('<a class="btn btn-danger btn-xs ' + rollbackAuditFlag + '" href="#" onclick="rollbackAudit(\'' + row.appId + '\')"><i class="fa fa-close">撤回审核</i></a> ');
                                break;
                            case 3:
                                actions.push('<a class="btn btn-primary btn-xs ' + releaseAuditFlag + '" href="#" onclick="releaseAudit(\'' + row.appId + '\')"><i class="fa fa-check">发布</i></a> ');
                                break;
                            default:
                                break;
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 提交代码审核 */
    function submitAudit(commitId) {
        var url = prefix+'/submitAudit/' + commitId;
        $.modal.open("提交代码审核", url);
    }

    /* 撤回审核 */
    function rollbackAudit(commitId) {
        var url = prefix+'/rollbackAudit/' + commitId;

    }

    /* 发布审核 */
    function releaseAudit(commitId) {
        var url = prefix+'/releaseAudit/' + commitId;

    }
    /* 批量上传代码并生成体验版 */
    function mutiCommit() {
        let rows = $.table.selectColumns('shopId');
        let shopIdStr = rows.join();
        $.modal.confirm("共选择了【"+rows.length+"】个小程序，请确认是否批量生成体验版？", function () {
            var url = prefix+'/commit/' + shopIdStr;
            $.modal.open("上传代码并生成体验版", url);
        });
    }

</script>
</body>
</html>